package com.mingxi.backend.controller;

import com.mingxi.backend.common.Result;
import com.mingxi.backend.pojo.entity.SelectCourse;
import com.mingxi.backend.pojo.vo.CourseStuInfo;
import com.mingxi.backend.service.SelectCourseService;
import com.mingxi.backend.service.StuCourseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController()
@RequestMapping("/api/v1/teacher")
public class TeacherController {

    @Resource
    private SelectCourseService selectCourseService;
    @Resource
    private StuCourseService stuCourseService;

    @GetMapping("/course/info")
    public Result getCourseStuInfo(@RequestParam int selectCourseId){
        List<CourseStuInfo> stuInfos =  selectCourseService.getCourseStuInfo(selectCourseId);
        return Result.success(stuInfos);
    }

    @PostMapping("/course/info")
    public Result setCourseGrade(@RequestParam int stuCourseId, @RequestParam int grade){
        stuCourseService.updateCourseGrade(stuCourseId, grade);
        return Result.success("上传成绩成功！");
    }

    @GetMapping("/course/myCourse")
    public Result getMyCourse(@RequestParam int teacherId){
        List<SelectCourse> selectCourses = selectCourseService.getCourseByTeacherId(teacherId);
        return Result.success(selectCourses);
    }
}
